document.addEventListener('DOMContentLoaded', function () {
    const urlInput = document.getElementById('urlInput');
    const startBtn = document.getElementById('startBtn');

    // 页面加载时读取并填充历史记录
    const savedUrl = localStorage.getItem('savedUrl');
    if (savedUrl) {
        urlInput.value = savedUrl;
    }

    // 点击“开始监控”时保存当前输入内容
    startBtn.addEventListener('click', function () {
        const currentUrl = urlInput.value.trim();
        if (currentUrl) {
            localStorage.setItem('savedUrl', currentUrl);
        }
    });
});


document.getElementById('startBtn').addEventListener('click', () => {
    const url = document.getElementById('urlInput').value;
    if (!url) return alert('请输入网址');

    chrome.runtime.sendMessage({action: 'startMonitoring', url});
});

document.getElementById('stopBtn').addEventListener('click', () => {
    chrome.runtime.sendMessage({action: 'stopMonitoring'}, () => {
        chrome.windows.create({url: 'display.html', type: 'popup', width: 800, height: 600});
    });
});
